﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SimpleUnitity.Cache
{
    [Serializable]
    public class AppDomainCache: WarpCache, ICache
    {
        private AppDomainCache(ICache cache)
            : base(cache)
        {
        }

        static readonly string domainKey = string.Format("__SimpleUnitity_Cache_AppDomainCache_Current_RANDON_{0}_", new Random().NextDouble());

        public static ICache Current
        {
            get
            {
                NormalCache cache = AppDomain.CurrentDomain.GetData(domainKey) as NormalCache;
                if (cache == null)
                {
                    cache = new NormalCache();
                    AppDomain.CurrentDomain.SetData(domainKey, cache);
                }
                return new AppDomainCache(cache);
            }
        }
    }
}
